﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Chefbook.DataObjects;
using NUnit.Framework;
using Rhino.Mocks;

using Chefbook.UserActions;
using Chefbook.ViewModels;

namespace UnitTests.UserActionsTests
{
    [TestFixture]
    public class CreateCategoryActionFixture
    {
        private MockRepository mocks;
        private IUserAction action;
        private CategoryViewModel category, presubcat;
        

        [SetUp]
        public void Init()
        {
            mocks = new MockRepository();
            

            category = new CategoryViewModel(new Category(null)) { Name = "root" };
            presubcat = new CategoryViewModel(new Category(category.CategoryModel));
            Assert.AreEqual(1, category.Subcategories.Count);
            Assert.Contains(presubcat, category.Subcategories);

            action = new CreateCategoryAction(category, "New Category") ;
        }

        [Test]
        public void DoActionTest()
        {
            action.DoAction();
            Assert.AreEqual(2, category.Subcategories.Count);
            Assert.Contains(presubcat, category.Subcategories);
            var newCategory = category.Subcategories.First(x => x.CategoryModel != presubcat.CategoryModel);
            Assert.AreEqual(category, newCategory.Parent);
            Assert.AreEqual("New Category", newCategory.Name);
        }

        [Test]
        public void UndoActionTest()
        {
            action.DoAction();
            action.UndoAction();
            Assert.AreEqual(1, category.Subcategories.Count);
            Assert.Contains(presubcat, category.Subcategories);
        }

        [Test]
        public void UndoActionWithoutDoingTest()
        {
            UserActionTestsHelper.UndoActionWithoutDoingTest(action);
        }

        [Test]
        public void UndoActionTwiceAfterDoingTest()
        {
            UserActionTestsHelper.UndoActionTwiceAfterDoingTest(action);
        }

        [Test]
        public void DoActionTwiceTest()
        {
            UserActionTestsHelper.DoActionTwiceTest(action);
        }

        [Test]
        public void ActionNameTest()
        {
            Assert.AreEqual(string.Format("Create Subcategory in Category '{0}'", category), action.ToString());
        }
    }
}
